package com.spring.api.web.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.aliyun.oss.OSSClient;
import com.google.common.collect.Maps;
import com.spera.aliyunContent.AliyunContent;
import com.spera.aliyunUtil.CreateOSSClient;
import com.spera.aliyunUtil.SperaOSSUtil;
import com.spera.genutil.IdentifyCodeUtil;
import com.spera.genutil.SpUtil;
import com.spera.genutil.Token;
import com.spera.genutil.TokenUtil;
import com.spring.api.web.dao.ApiUserDetailMapper;
import com.spring.api.web.model.ApiUser;
import com.spring.api.web.service.UserApiService;
import com.spring.security.core.annotation.Log;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.core.util.UDate;
import com.spring.security.core.util.UpdateMap;
import com.spring.security.web.dao.CommonMapper;
import com.spring.security.web.dao.JedisCache;
import com.spring.security.web.dao.RoleMapper;
import com.spring.security.web.dao.UserMapper;
import com.spring.security.web.model.Ihuyi;
import com.spring.security.web.model.Status;
import com.spring.security.web.model.User;
import com.spring.security.web.service.IhuyiService;
import com.spring.sperapc.web.dao.FamilyMapper;
import com.spring.sperapc.web.dao.FamilyMemberMapper;
import com.spring.sperapc.web.dao.TracelogboMapper;
import com.spring.sperapc.web.model.Family;
import com.spring.sperapc.web.model.FamilyMember;
import com.spring.sperapc.web.model.TracelogboWithBLOBs;
import com.spring.tools.MyTools;

@Service
public class UserApiServiceImpl implements UserApiService {
	static Logger logger = Logger.getLogger(UserApiServiceImpl.class.getName());
	@Resource
	private ApiUserDetailMapper apiUserDetailMapper;

	@Resource
	private JedisCache jedisCache;

	@Resource
	private UserMapper userMapper;

	@Resource
	private RoleMapper roleMapper;
	
	@Resource
	private IhuyiService ihuyiServiceImpl;
	
    @Resource
    private FamilyMapper familyMapper;

    @Resource
    private FamilyMemberMapper familyMemberMapper;
    
    @Resource
    private CommonMapper commonMapper;
    
    @Resource
    private TracelogboMapper tracelogboMapper;
    
	@Resource
	private MongoTemplate mongoService;
	
	@Override
	public Map<String, Object> login(String token, String ismobile,String userName,
			String passWord,String valnum,String deviceCategory,HttpServletRequest request) throws Exception{
		if(deviceCategory==null){
			deviceCategory="99";
		}
		
		Map<String, Object> m = ApplicationUtils.getDataSet();
		
		if (ApplicationUtils.isNotNull(token)) {
			Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
			if(ApplicationUtils.isNotNull(s)){
				return s;
			}else{
				m.put("token", token);
				String id=jedisCache.hget(token,TokenUtil.USER_ID);
				//刷新token时间
				logger.info("user_id:"+id);
				User u = new User();
				u.setId(id);
				ApiUser au= apiUserDetailMapper.selectUserDetail(id);
				m.put(ApplicationUtils.DATASET, au);
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "登录成功");
				return m;
			}
		}

		if ((!ApplicationUtils.isNotNull(userName))
				|| (!ApplicationUtils.isNotNull(passWord))) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "用户名或密码不能为空");
			return m;
		}
		
		User s = new User();
		s.setUsername(userName);

		if(StringUtils.isBlank(ismobile)){
			if(IdentifyCodeUtil.checkNeedIdentify(userName, jedisCache)){//判断是否需要登录校验
				if(!IdentifyCodeUtil.checkIdentifyCode(userName, jedisCache,valnum)){//验证校验码
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "验证码输入有误");
					m.put("valstatus", IdentifyCodeUtil.checkIdentifyStatus(userName,jedisCache));
					return m;
				}
			}
		}

		List<User> list = this.userMapper.checkUser(s);
		User authUserInfo = null;
		if ((ApplicationUtils.isNotNull(list)) && (list.size() != 0)) {
			authUserInfo = (User) list.get(0);
		}
		if (!ApplicationUtils.isNotNull(authUserInfo)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "用户名不存在");
			return m;
		}
		
		if (!passWord.equalsIgnoreCase(authUserInfo.getPassword())) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "密码错误");
			m.put("valstatus", IdentifyCodeUtil.checkIdentifyStatus(userName,jedisCache));
			return m;
		}
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "登录成功");
	

		
		IdentifyCodeUtil.logSuccess(userName, jedisCache);//清除验证码记录信息
		ApiUser dataSet = this.apiUserDetailMapper
				.selectUserDetail(authUserInfo.getId());
		if(dataSet!=null){
			Token tsession = new Token();
			tsession.setUser_id(dataSet.getC_user_id()).setUser_name(dataSet.getUsername()).setRole_id(dataSet.getC_role_id())
					.setFamily_id(dataSet.getC_family_id()).setMember_name(dataSet.getMember_name()).
					setDeviceCategory(deviceCategory);;
			String user_uuid = TokenUtil.SetSperaToken(null,jedisCache, tsession,TokenUtil.CUS_LOGIN);
			m.put(ApplicationUtils.DATASET, dataSet);
			m.put("token", user_uuid);
			
			TracelogboWithBLOBs tl = MyTools.getLog(jedisCache, user_uuid, request);
			tl.setEntitytypename("c_family_member");
			tl.setEntityid(authUserInfo.getId());
			tl.setLogcategory(6);
			tl.setDevicecategory(Integer.parseInt(deviceCategory));
			tl.setLogdescription(null);
			int effect=tracelogboMapper.insert(tl);
			System.out.println(effect);
		}
		return m;
	}
	
	@Override
	@Log("UserApiServiceImpl:function[queryUserDetail]")
	public Map<String, Object> queryUserDetail(String token) throws Exception{
		Map<String, Object> m = ApplicationUtils.getDataSet();
		if (ApplicationUtils.isNotNull(token)) {
			Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
			if(ApplicationUtils.isNotNull(s)){
				return s;
			}else{
				String id=jedisCache.hget(token,TokenUtil.USER_ID);
				ApiUser au= apiUserDetailMapper.selectUserDetail(id);
				m.put(ApplicationUtils.DATASET, au);
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "查询成功");
//				ApiUser dataSet = this.apiUserDetailMapper
//						.selectUserDetail(id);
//				m.put("dataset", dataSet);
			}
		}
		return m;
	}
	
//	@Override
//	public Map<String, Object> register(User user, MultipartFile file) {
//		String role_id = "1";
//		Map<String, Object> m = new HashMap<String, Object>();
//		if (!ApplicationUtils.isNotNull(role_id)) {
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "请选择角色");
//			return m;
//		}
//		String user_id = ApplicationUtils.randomUUID();
//		user.setId(user_id);
//		user.setState("1");
//		try {
//			User s = new User();
//			s.setUsername(user.getUsername());
//			List<User> list = this.userMapper.selectByWhereStr(user);
//			User is_exists = null;
//			if ((ApplicationUtils.isNotNull(list)) && (list.size() != 0)) {
//				is_exists = (User) list.get(0);
//			}
//
//			if (ApplicationUtils.isNotNull(is_exists)) {
//				m.put(ApplicationUtils.STATUS, "0");
//				m.put(ApplicationUtils.MSG, "用户已存在");
//				return m;
//			}
//			if (!file.isEmpty()) {
//				String fileName = file.getOriginalFilename();
//				Date d = new Date();
//				SimpleDateFormat tempDate = new SimpleDateFormat(
//						"yyyyMMddHHmmss");
//				String newfilename = tempDate.format(d) + "_" + fileName;
//				Integer fileSize = Integer.valueOf(0);
//				File filePath = null;
//				byte[] bytes = file.getBytes();
//				fileSize = Integer.valueOf((int) file.getSize() / 1024);
//				if (fileSize.intValue() <= 102400) {
//					String uploadPath = "\\upload\\";
//
//					if (!new File(uploadPath).isDirectory()) {
//						new File(uploadPath).mkdir();
//					}
//					uploadPath = uploadPath + newfilename;
//					filePath = new File(uploadPath);
//					FileCopyUtils.copy(bytes, filePath);
//					user.setImage_src(JedisCont.APP_ADDRESS + newfilename);
//				} else {
//					m.put(ApplicationUtils.STATUS, "0");
//					m.put(ApplicationUtils.MSG, "上传的文件太大，文件大小不能超过10M");
//					return m;
//				}
//			}
//			int in = insert(user, role_id);
//			if (in == 1) {
//				String user_uuid = PWD.createNewPassword(ApplicationUtils
//						.randomUUID());
//				this.jedisCache.setEx(user_uuid, JedisCont.JEDIS_EXPRISE,
//						user_id);
//				String token = user_uuid;
//				m.put("token", token);
//				m.put(ApplicationUtils.STATUS, "1");
//				m.put(ApplicationUtils.MSG, "注册成功");
//			} else {
//				m.put(ApplicationUtils.STATUS, "0");
//				m.put(ApplicationUtils.MSG, "数据保存异常");
//			}
//			ApiUser dataSet = this.apiUserDetailMapper
//					.selectUserDetail(user_id);
//			m.put("dataSet", dataSet);
//		} catch (Exception e) {
//			e.printStackTrace();
//			m.put(ApplicationUtils.STATUS, "0");
//			m.put(ApplicationUtils.MSG, "用户注册失败");
//		}
//		return m;
//	}

	/**
	 * 
	 * @param model
	 * @param role_id
	 * @param isLock 是否不通过手机验证直接注册（此种注册的用户状态为不启用，需要手动启用后方可登录）
	 * @throws Exception 
	 */
	@Log("UserApiServiceImpl:function[insertUserFamily]")
	public void insertUserFamily(User model, String role_id,boolean isLock,HttpServletRequest request) throws Exception {
//		int u = this.userMapper.insertSelective(model);
//		Map<String, Object> m = new HashMap<String, Object>();
//		m.put("user_id", model.getId());
//		m.put("role_id", role_id);
//		int r = this.roleMapper.insertUserRole(m);
//		int ret = 0;
//		//判断用户是否新增成功
//		if ((u == 1) && (r == 1)) {
//			ret = 1;
			//判断家庭是否已存在
//			Map<String, String> s = new HashMap<String, String>();
//			s.put("c_user_id", model.getId());
//			Family isIn = familyMapper.selectByPrimaryKey(s);
//			if(!ApplicationUtils.isNotNull(isIn)){//用户新增成功，新增家庭信息
				Family family = new Family();
				family.setFamilyName(model.getPhone()+"用户家庭");
				String familyId = ApplicationUtils.randomUUID();
				family.setId(familyId);
				family.setWx_point(new BigDecimal(0));
//				family.setC_user_id(model.getId());
				int f = familyMapper.insertSelective(family);
				
				TracelogboWithBLOBs tlw = MyTools.getLogByRequest(request);
				tlw.setInitialoperatorid(model.getId());
				tlw.setInitialoperatorname(model.getPhone());
				tlw.setEntitytypename("c_family");
				tlw.setEntityid(familyId);
				tlw.setLogcategory(1);
				tlw.setLogdescription(MyTools.getChangeByObject(family,"新增"));
				int effect=tracelogboMapper.insert(tlw);
				
				if(f==1){//家庭保存成功，新增当前注册用户未加成成员
					FamilyMember fm = new FamilyMember();
					fm.setcFamilyId(familyId);
					fm.setMemberName(model.getPhone()+"用户");
					String realName = ApplicationUtils.isNotNull(model.getReal_name())?
							model.getReal_name():model.getPhone()+"用户";
					fm.setReal_name(realName.trim());
					fm.setC_user_id(model.getId());
					fm.setcRoleId(role_id);
					fm.setUsername(model.getPhone().trim());
					fm.setPhone(model.getPhone().trim());
					fm.setPassword(model.getPassword().trim());
					fm.setKids_parkid(model.getKids_parkid());//辅导员先下帮客户注册时用
					if(isLock){
						fm.setT_user_id(model.getT_user_id());
						fm.setT_username(model.getT_username().trim());
						fm.setAdmission_note(model.getAdmission_note());
						fm.setAdmission_way(model.getAdmission_way());
						fm.setAdmission_way_id(model.getAdmission_way_id());
						fm.setEntityAvailableState("10");
						
//						fm.setEntityAvailableState("20");//用户锁定状态
					}else{
						fm.setEntityAvailableState("10");
					}
					familyMemberMapper.insertSelective(fm);
					
					TracelogboWithBLOBs tl = MyTools.getLogByRequest(request);
					tl.setEntitytypename("c_family_member");
					tl.setInitialoperatorid(model.getId());
					tl.setInitialoperatorname(model.getPhone());
					tl.setEntityid(model.getId());
					tl.setLogcategory(1);
					tl.setLogdescription(MyTools.getChangeByObject(fm,"新增"));
					int effect2=tracelogboMapper.insert(tl);
					System.out.println(effect2);
				}
//			}
//		}
	}

	/**
	 * 用户注册
	 */
	@Override
	@Log("UserApiServiceImpl:function[register]")
	public Map<String, Object> register(User user,String valnum,String deviceCategory,HttpServletRequest request) throws Exception{
		Map<String, Object> m = new HashMap<String, Object>();
		
		if (!ApplicationUtils.isNotNull(valnum)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入短信验证码");
			return m;
		}
		
		String user_id = ApplicationUtils.randomUUID();
		user.setId(user_id);
		User s = new User();
		
		if (ApplicationUtils.isNotNull(user.getPhone())) {
			if (SpUtil.validatePhone(user.getPhone())) {
				s.setUsername(user.getPhone());
				s.setPhone(user.getPhone());
			} else {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请输入正确的手机号");
				return m;
			}
		} else {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入手机号");
			return m;
		}
		
		if(!jedisCache.exists(user.getPhone())){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码已过期，请重新发送");
			return m;
		}
		
		String val_num = jedisCache.get(user.getPhone());
		if(!valnum.equals(val_num)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码不正确");
			return m;
		}

		List<User> list = this.userMapper.selectByWhereStr(s);
		if ((ApplicationUtils.isNotNull(list)) && (list.size() > 0)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "用户已存在");
			return m;
		}
		
		if (!ApplicationUtils.isNotNull(user.getPassword())) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "密码不可为空");
			return m;
		}
		
		List<User> listp = this.userMapper.selectByPhone(s);
		if ((ApplicationUtils.isNotNull(listp)) && (listp.size() > 0)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "该手机号已被注册");
			return m;
		}
		
		//默认角色为1=爸爸
		insertUserFamily(user, "1",false,request);
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "注册成功");
		ApiUser dataSet = this.apiUserDetailMapper
				.selectUserDetail(user_id);
		if(dataSet!=null){
			Token tsession = new Token();
			tsession.setUser_id(dataSet.getC_user_id()).setUser_name(dataSet.getUsername()).setRole_id(dataSet.getC_role_id())
					.setFamily_id(dataSet.getC_family_id()).setMember_name(dataSet.getMember_name()).
					setDeviceCategory(deviceCategory);
			String token = TokenUtil.SetSperaToken(null,jedisCache, tsession,TokenUtil.CUS_LOGIN);

			m.put(ApplicationUtils.DATASET, dataSet);
			m.put("token", token);
		}
		return m;
	}

	
	
	@Override
	@Log("UserApiServiceImpl:function[registerByInviteCode]")
	public Map<String, Object> registerByInviteCode(User user,String valnum,String inviteCode,String deviceCategory,HttpServletRequest request) throws Exception{
		Map<String, Object> m = new HashMap<String, Object>();

		
		if (!ApplicationUtils.isNotNull(valnum)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入短信验证码");
			return m;
		}
		
		String user_id = ApplicationUtils.randomUUID();
		user.setId(user_id);
		User s = new User();
		
		if (ApplicationUtils.isNotNull(user.getPhone())) {
			if (SpUtil.validatePhone(user.getPhone())) {
//				s.setPhone(user.getPhone());
				s.setUsername(user.getPhone());
				s.setPhone(user.getPhone());
			} else {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请输入正确的手机号");
				return m;
			}
		} else {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入手机号");
			return m;
		}
		
		if(!jedisCache.exists(user.getPhone())){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码已过期，请重新发送");
			return m;
		}
		
		String val_num = jedisCache.get(user.getPhone());
		if(!valnum.equals(val_num)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码不正确");
			return m;
		}

		List<User> list = this.userMapper.selectByWhereStr(s);
		if ((ApplicationUtils.isNotNull(list)) && (list.size() > 0)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "用户已存在");
			return m;
		}
		
		if (!ApplicationUtils.isNotNull(user.getPassword())) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "密码不可为空");
			return m;
		}
		
		List<User> listp = this.userMapper.selectByPhone(s);
		if ((ApplicationUtils.isNotNull(listp)) && (listp.size() > 0)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "该手机号已被注册");
			return m;
		}
		
		//注册家庭成员如果valum!=null
		if(inviteCode!=null&&!inviteCode.equals("")){
			//使用了优惠码
			HashMap<String,Object> hm=new HashMap<String,Object>();
			hm.put("c_user_id", user.getId());
			hm.put("inviteCode", inviteCode);
			
			
			List<Map<String,Object>> familyID=apiUserDetailMapper.getFamilyByCode(inviteCode);
			
			if(familyID==null||familyID.size()==0){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请输入有效的邀请码");		
				return m;
			}
//			String c_role_id=apiUserDetailMapper.getRoleByID(user.getId());
			String c_role_id=ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_role_id"));
			
			if(c_role_id!=null){			
				if(c_role_id.equals("2")||c_role_id.equals("1")){
					HashMap<String,Object> hm2=new HashMap<String,Object>();
					hm2.put("c_role_id", c_role_id);
					hm2.put("c_family_id", ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_family_id")));
					
					int count=apiUserDetailMapper.getRoleCount(hm2);
					if(count>0){
						m.put(ApplicationUtils.STATUS, "0");
						m.put(ApplicationUtils.MSG, "该家庭已有父母，不能重复添加父母角色");		
						return m;
					}
				}
			}
			HashMap<String,Object> hm3=new HashMap<String,Object>();
			hm3.put("c_user_id", user.getId());
			hm3.put("c_family_id", ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_family_id")));
			
			HashMap<String,Object> hm4=new HashMap<String,Object>();
			
			hm4.put("user_id", user.getId());
			hm4.put("family_id", ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_family_id")));
			hm4.put("code", inviteCode);
			
			apiUserDetailMapper.updateCode(hm4);
			//改用户
			FamilyMember fm = new FamilyMember();
			fm.setcFamilyId(ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_family_id")));
			fm.setMemberName(user.getPhone()+"用户");
			String realNmae = ApplicationUtils.isNotNull(user.getReal_name())?
					user.getReal_name():user.getPhone()+"用户";
			fm.setReal_name(realNmae);
			fm.setC_user_id(user.getId());
			fm.setcRoleId(c_role_id);
			fm.setUsername(user.getPhone());
			fm.setPhone(user.getPhone());
			fm.setPassword(user.getPassword());
			fm.setKids_parkid(user.getKids_parkid());//辅导员先下帮客户注册时用
				fm.setEntityAvailableState("10");
			familyMemberMapper.insertSelective(fm);
			
			TracelogboWithBLOBs tl = MyTools.getLogByRequest(request);
			tl.setEntitytypename("c_family_member");
			tl.setEntityid(user.getId());
			tl.setLogcategory(1);
			tl.setLogdescription(MyTools.getChangeByObject(fm, "新增"));
			int effect=tracelogboMapper.insert(tl);
			System.out.println(effect);
			
			
			if(StringUtils.isNotBlank(inviteCode)){//如果是邀请，则记录日志
				hm.put("c_role_id", c_role_id);
				apiUserDetailMapper.addinviteCodeLog(hm);
			}
		}else{
			//默认角色为1=爸爸
			insertUserFamily(user, "1",false,request);
		}

		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "注册成功");
		ApiUser dataSet = this.apiUserDetailMapper
				.selectUserDetail(user_id);
		if(dataSet!=null){
			Token tsession = new Token();
			tsession.setUser_id(dataSet.getC_user_id()).setUser_name(dataSet.getUsername()).setRole_id(dataSet.getC_role_id())
					.setFamily_id(dataSet.getC_family_id()).setMember_name(dataSet.getMember_name())
					.setDeviceCategory(deviceCategory);
			String token = TokenUtil.SetSperaToken(null,jedisCache, tsession,TokenUtil.CUS_LOGIN);

			m.put(ApplicationUtils.DATASET, dataSet);
			m.put("token", token);
		}
		return m;
	}

	
	
	
	
	
	
	/**
	 * 密码修改,需要发送验证码
	 */
	@Override
	@Log("UserApiServiceImpl:function[changePwd]")
	public Map<String,Object> changePwd(String token,
			String pwd_token,
			String pwd_valnum,
			String oldpwd, 
			String newpwd,
			HttpServletRequest request) throws Exception{
		Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
		if(ApplicationUtils.isNotNull(s))
			return s;
		s = new HashMap<String, Object>();
		
		if (!ApplicationUtils.isNotNull(newpwd)) {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "密码不可为空");
			return s;
		}
		
		String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
		User u = new User();
		u.setId(user_id);
		
		List<User> list = userMapper.selectById(u);
		
		if (!ApplicationUtils.isNotNull(list)||list.size()==0) {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "用户名不存在");
			return s;
		}
		
		if ((ApplicationUtils.isNotNull(list)) && (list.size() != 0)) {
			u = (User) list.get(0);
		}
		
		//密码找回与密码修改的区别
		if(ApplicationUtils.isNotNull(oldpwd)){
			if(!oldpwd.equals(u.getPassword())){
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "旧密码输入不正确");
				return s;
			}
		}
		else{
			if(!ApplicationUtils.isNotNull(pwd_token)){
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "请先发送验证码");
				return s;
			}
			
			if(!ApplicationUtils.isNotNull(pwd_valnum)){
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "验证码不能为空");
				return s;
			}
			
			if(!jedisCache.exists(pwd_token)){
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "验证码已失效，请重新发送");
				return s;
			}
			
			String val_token = jedisCache.lindex(pwd_token, 0);
			String val_num = jedisCache.lindex(pwd_token, 1);
			if(!val_token.equals(token)){
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "此验证码不归该用户所有，请重新发送");
				return s;
			}
			
			if(!val_num.equals(pwd_valnum)){
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "验证码不一致");
				return s;
			}
		}
		
//		User nu = new User();
//		nu.setId(user_id);
//		nu.setPassword(newpwd);
		UpdateMap up = new UpdateMap("c_family_member");
		up.addField("password", newpwd);
		up.addWhere("c_user_id", user_id);
		int uu = commonMapper.update(up);
//		int uu = userMapper.updateByPrimaryKeySelective(nu);
		if(uu>0){
			s.put(ApplicationUtils.STATUS, "1");
			s.put(ApplicationUtils.MSG, "密码修改成功");
			
			TracelogboWithBLOBs tl = MyTools.getLog(jedisCache, token, request);
			tl.setEntitytypename("c_family_member");
			tl.setEntityid(user_id);
			tl.setLogcategory(2);
			tl.setLogdescription("password:"+newpwd);
			int effect=tracelogboMapper.insert(tl);
			System.out.println(effect);		
		}else{
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "密码修改失败");
		}
		return s;
	}
	
	/**
	 * 发送验证码
	 */
	@Log("UserApiServiceImpl:function[sendPwdToken]")
	public Map<String, Object> sendPwdToken(String token,String type)throws Exception{
		Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
		if(ApplicationUtils.isNotNull(s))
			return s;
		s = new HashMap<String, Object>();
		
//		String user_id=jedisCache.lindex(token, 0);
		String user_id=jedisCache.hget(token,TokenUtil.USER_ID);
		ApiUser au= apiUserDetailMapper.selectUserDetail(user_id);
		if(!ApplicationUtils.isNotNull(au.getPhone())){
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "用户手机号未维护");
			return s;
		}
		String pwd_token = "findpwd_"+au.getPhone();
		
		if(jedisCache.exists(pwd_token)){
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "验证码已发送，3分钟后可再次发送");
			return s;
		}else{
			int[] arrNum = ApplicationUtils.randomArray(0, 9, 6);
			String pwd_valnum = String.valueOf(arrNum[0])+
					String.valueOf(arrNum[1])+
					String.valueOf(arrNum[2])+
					String.valueOf(arrNum[3])+
					String.valueOf(arrNum[4])+
					String.valueOf(arrNum[5]);
			jedisCache.rpush(pwd_token, token);
			jedisCache.rpush(pwd_token, pwd_valnum);
			jedisCache.expire(pwd_token, 180);
			Ihuyi info = new Ihuyi();
			info.setMobile(au.getPhone());
			String content = "您的验证码是：【"+pwd_valnum+"】。请不要把验证码泄露给其他人。";
			info.setContent(content);
			Status st = ihuyiServiceImpl.sendSms(info);
//			Status st = new Status();
//			st.setStatus("0");
			if("0".equalsIgnoreCase(st.getStatus())){
				s.put("pwd_token", pwd_token);
//				s.put("pwd_valnum", pwd_valnum);
				s.put(ApplicationUtils.STATUS, "1");
				s.put(ApplicationUtils.MSG, "验证码发送成功");
				
				//短信日志
				SpUtil.setPhoneLog(mongoService,"1",au.getPhone(),pwd_valnum,content);
				
				return s;
			}else{
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "验证码发送失败");
				
				//短信日志
				SpUtil.setPhoneLog(mongoService,"0",au.getPhone(),pwd_valnum,content);
				
				return s;
			}
		}
	}

	/**
	 * 根据手机号发送验证码
	 */
	@Override
	@Log("UserApiServiceImpl:function[sendPhoneToken]")
	public Map<String, Object> sendPhoneToken(String phone,String type) throws Exception{

		int valTime = 600;
		String valTimeStr = "10";
		int overTime = 120;
		//String overTimeStr = "2";
		Map<String, Object> s = new HashMap<String, Object>();
		
		if (ApplicationUtils.isNotNull(phone)) {
			if (!SpUtil.validatePhone(phone)) {
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "请输入正确的手机号");
				return s;
			}
		} else {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "请输入手机号");
			return s;
		}
		
		/**
		 * type:1需要检测手机用户存不存在
		 */
		if("1".equalsIgnoreCase(type)){
			User u = new User();
			u.setPhone(phone);
			List<User> listp = this.userMapper.selectByPhone(u);
			if (ApplicationUtils.isNotNull(listp) &&(listp.size() > 0)) {
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "该手机号已被注册");
				return s;
			}
		}
		if("2".equalsIgnoreCase(type)){
			User u = new User();
			u.setPhone(phone);
			List<User> listp = this.userMapper.selectByPhone(u);
			if (!ApplicationUtils.isNotNull(listp) ||(listp.size() == 0)) {
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "该手机号不存在");
				return s;
			}
		}
			int[] arrNum = ApplicationUtils.randomArray(0, 9, 6);
			String pwd_valnum = String.valueOf(arrNum[0])+
					String.valueOf(arrNum[1])+
					String.valueOf(arrNum[2])+
					String.valueOf(arrNum[3])+
					String.valueOf(arrNum[4])+
					String.valueOf(arrNum[5]);
			jedisCache.setEx(phone, valTime, pwd_valnum);
			jedisCache.setEx(phone+"_HASVAL", overTime, pwd_valnum);
			Ihuyi info = new Ihuyi();
			info.setMobile(phone);
//			String content = "您的验证码是：【"+pwd_valnum+"】。请不要把验证码泄露给其他人。";
			String content = "您的验证码是："+pwd_valnum+"。请在"+valTimeStr+"分钟内使用，请不要把验证码泄露给其他人！";
			info.setContent(content);
			Status st = ihuyiServiceImpl.sendSms(info);
			if("0".equalsIgnoreCase(st.getStatus())){
				s.put(ApplicationUtils.STATUS, "1");
				s.put(ApplicationUtils.MSG, "验证码发送成功");
				SpUtil.setPhoneLog(mongoService,"1",phone,pwd_valnum,content);
				jedisCache.setEx("sendPhoneToken_"+phone, 120, pwd_valnum);
				return s;
			}else{
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "验证码发送失败");
				SpUtil.setPhoneLog(mongoService,"0",phone,pwd_valnum,content);
				return s;
			}
	}
	
	
	/**
	 * 根据手机号发送验证码
	 */
	@Override
	@Log("UserApiServiceImpl:function[findPhoneToken]")
	public Map<String, Object> findPhoneToken(String phone) throws Exception{

		int valTime = 600;
		String valTimeStr = "10";
		int overTime = 120;
		//String overTimeStr = "2";
		Map<String, Object> s = new HashMap<String, Object>();

		if (ApplicationUtils.isNotNull(phone)) {
			if (!SpUtil.validatePhone(phone)) {
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "请输入正确的手机号");
				return s;
			}
		} else {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "请输入手机号");
			return s;
		}
		
		/**
		 * 需要检测手机用户存不存在
		 */
		User u = new User();
		u.setPhone(phone);
		List<User> listp = this.userMapper.selectByPhone(u);
		if (!ApplicationUtils.isNotNull(listp) ||(listp.size() == 0)) {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "该手机号不存在");
			return s;
		}

			int[] arrNum = ApplicationUtils.randomArray(0, 9, 6);
			String pwd_valnum = String.valueOf(arrNum[0])+
					String.valueOf(arrNum[1])+
					String.valueOf(arrNum[2])+
					String.valueOf(arrNum[3])+
					String.valueOf(arrNum[4])+
					String.valueOf(arrNum[5]);
			jedisCache.setEx(phone, valTime, pwd_valnum);
			jedisCache.setEx(phone+"_HASVAL", overTime, pwd_valnum);
			Ihuyi info = new Ihuyi();
			info.setMobile(phone);
			String content = "您的验证码是："+pwd_valnum+"。请在"+valTimeStr+"分钟内使用，请不要把验证码泄露给其他人！";
			info.setContent(content);
			Status st = ihuyiServiceImpl.sendSms(info);
			if("0".equalsIgnoreCase(st.getStatus())){
				s.put(ApplicationUtils.STATUS, "1");
				s.put(ApplicationUtils.MSG, "验证码发送成功");
				SpUtil.setPhoneLog(mongoService,"1",phone,pwd_valnum,content);
				
				return s;
			}else{
				s.put(ApplicationUtils.STATUS, "0");
				s.put(ApplicationUtils.MSG, "验证码发送失败");
				SpUtil.setPhoneLog(mongoService,"0",phone,pwd_valnum,content);
				return s;
			}
	}
	

	/**
	 * 密码找回
	 */
	@Override
	@Log("UserApiServiceImpl:function[findPwd]")
	public Map<String, Object> findPwd(String phone,String val_num, String newpwd,String deviceCategory) throws Exception{
		
		Map<String,Object> m = ApplicationUtils.getDataSet();
		if(!ApplicationUtils.isNotNull(phone)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "手机号不可为空");
			return m;
		}
		if(!ApplicationUtils.isNotNull(newpwd)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "新密码不可为空");
			return m;
		}
		User s = new User();
		s.setPhone(phone);
		
/*		if(!jedisCache.exists(phone)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码已过期，请重新发送");
			//return m;
		}
		
		if(!ApplicationUtils.isNotNull(val_num)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码不可为空");
			//return m;
		}
		
		String cval_num = jedisCache.get(phone);
		if(!cval_num.equals(val_num)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码不正确");
			//return m;
		}
*/
		List<User> listp = this.userMapper.selectByPhone(s);
		if (listp==null||listp.size()==0) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "该手机号用户不存在或用户未绑定手机，如有需求，请联系工作人员");
			return m;
		}
		
		s.setPassword(newpwd);
		int uu = userMapper.updateByPrimaryKeySelective(s);
		if(uu>0){
			//手机号登录
			ApiUser dataSet = this.apiUserDetailMapper
					.selectUserDetailByPhone(phone);
			String user_uuid = ApplicationUtils.randomUUID();
			
			if(dataSet!=null){

				
				Token tsession = new Token();
				tsession.setUser_id(dataSet.getC_user_id()).setUser_name(dataSet.getUsername()).setRole_id(dataSet.getC_role_id())
						.setFamily_id(dataSet.getC_family_id()).setMember_name(dataSet.getMember_name()).
						setDeviceCategory(deviceCategory);;
				
				TokenUtil.SetSperaToken(user_uuid,jedisCache, tsession,TokenUtil.CUS_LOGIN);
		
				m.put(ApplicationUtils.DATASET, dataSet);
				m.put("token", user_uuid);
			}
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "密码修改成功");
		}else{
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "密码修改失败");
		}
		
		return m;
	}

	/**
	 * 检测用户名，目前只针对手机用户
	 */
	@Override
	@Log("UserApiServiceImpl:function[checkUser]")
	public Map<String, Object> checkUser(String phone) throws Exception{
		Map<String,Object> m = ApplicationUtils.getDataSet();
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "用户可用");
		if(!ApplicationUtils.isNotNull(phone)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "用户名不可为空");
			return m;
		}
		User u = new User();
		u.setPhone(phone);
		List<User> list = this.userMapper.selectByWhereStr(u);
		if ((ApplicationUtils.isNotNull(list)) && (list.size() > 0)) {
			m.put("c_user_id", list.get(0).getId());
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "用户已存在");
		}
		return m;
	}

	/**
	 * 修改微信积分
	 */
	@Override
	@Log("UserApiServiceImpl:function[updateWxPoint]")
	public Map<String, Object> updateWxPoint(String token, String wx_point)throws Exception {
		Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
		if(ApplicationUtils.isNotNull(s))
			return s;
		s = new HashMap<String, Object>();
//		String c_family_id = jedisCache.lindex(token, 2);
		String c_family_id = jedisCache.hget(token, TokenUtil.FAMILY_ID);
		if(!ApplicationUtils.isNotNull(wx_point)){
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "微信积分不可为空");
			return s;
		}
		HashMap<String,Object> m=new HashMap<String,Object>();
		m.put("c_family_id", c_family_id);
		m.put("wx_point", wx_point);
		
		apiUserDetailMapper.updateWxPoint(m);
		s.put(ApplicationUtils.STATUS, "1");
		s.put(ApplicationUtils.MSG, "修改积分成功");
		return s;
	}

	/**
	 * 修改用户头像
	 */
	@Override
	@Log("UserApiServiceImpl:function[updateUserImageSrc]")
	public Map<String, Object> updateUserImageSrc(String token,String c_user_id,
			MultipartFile file,HttpServletRequest request) throws Exception {
		Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
		if(ApplicationUtils.isNotNull(s))
			return s;
		s = new HashMap<String, Object>();
		String user_id = jedisCache.hget(token,TokenUtil.USER_ID);
		if(!ApplicationUtils.isNotNull(c_user_id)){
			c_user_id = user_id;
		}
		Integer fileSize = (int) file.getSize() / 1024;
        if (fileSize >= 51200) {
        	s.put(ApplicationUtils.STATUS, "0");
            s.put(ApplicationUtils.MSG,"上传的文件太大，文件大小不能超过5M");
            return s;
        }
        
//        String oriFilePath = "";
//        String newFilePath = "";
        String filePath="";
        try{
        	//临时保存附件，并进行压缩
//    		String uploadPath = request.getSession().getServletContext()
//    				.getRealPath(AliyunContent.tempFilePath);
//
//    		if (!(new File(uploadPath).isDirectory())) {
//    			new File(uploadPath).mkdirs();
//    		}
//    		oriFilePath = uploadPath+File.separator+ApplicationUtils.randomUUID();
//    		
//    		File loFile = new File(oriFilePath);
//    		FileCopyUtils.copy(file.getBytes(), loFile);
//    		
//    		File newFile = new File(newFilePath);
//    		newFilePath = uploadPath+File.separator+ApplicationUtils.randomUUID();
//    		Thumbnails.of(loFile)
//            .size(160, 160)
//            .toFile(newFile);
    		
    		filePath = SperaOSSUtil.springFileUpOss(AliyunContent.fileBucket,"user_headimage/"+UDate.getDate()+"/"+ApplicationUtils.randomUUID(),file);
//    				(AliyunContent.fileBucket,"user_headimage/"+UDate.getDate()+"/"+ApplicationUtils.randomUUID(),newFile);
    		
        }catch(Exception e){
        	e.printStackTrace();
        }
//        finally{
//        	if(ApplicationUtils.isNotNull(oriFilePath)){
//        		SpUtil.deleteFile(oriFilePath);
//        	}
//        	if(ApplicationUtils.isNotNull(newFilePath)){
//        		SpUtil.deleteFile(newFilePath);
//        	}
//        }
        
		HashMap<String,Object> m=new HashMap<String,Object>();
		m.put("c_user_id", c_user_id);
		m.put("image_src", filePath);
		ApiUser uinfo = apiUserDetailMapper.selectUserDetail(c_user_id);
		//删除旧附件
		try{
			if(ApplicationUtils.isNotNull(uinfo.getImage_src())){
				String imageStr = uinfo.getImage_src().substring(uinfo.getImage_src().lastIndexOf("/")+1);
				OSSClient client = CreateOSSClient.getInstance().getOSSClient();
				SperaOSSUtil.deleteObject(client, AliyunContent.fileBucket, imageStr);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
		int i = apiUserDetailMapper.updateUserHeadImage(m);
		if(i==1){
			s.put("image_src",filePath);
			s.put(ApplicationUtils.STATUS, "1");
			s.put(ApplicationUtils.MSG, "修改头像成功");
		}else{
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "修改头像失败");
		}
		
		return s;
	}

	@Override
	@Log("UserApiServiceImpl:function[saveUserDetail]")
	public Map<String, Object> saveUserDetail(String token,ApiUser paramUser,HttpServletRequest request) throws Exception {
		Map<String, Object> s = TokenUtil.checkToken(token,jedisCache);
		if(ApplicationUtils.isNotNull(s))
			return s;
		s = new HashMap<String, Object>();
		String user_id = jedisCache.hget(token,TokenUtil.USER_ID);

		HashMap<String,Object> m=new HashMap<String,Object>();
		m.put("c_user_id", user_id);
		m.put("c_role_id", paramUser.getC_role_id());
		m.put("member_name", paramUser.getMember_name());
		m.put("real_name", paramUser.getReal_name());
		m.put("sex", paramUser.getSex());
		m.put("email", paramUser.getEmail());
		m.put("birthday", paramUser.getBirthday());
		m.put("education", paramUser.getEducation());
		m.put("work", paramUser.getWork());
		m.put("address", paramUser.getAddress());
		m.put("identity_card", paramUser.getIdentity_card());
		m.put("regionid", paramUser.getRegionid());
		
		int i = apiUserDetailMapper.saveUserDetail(m);
		if(i==0){
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "操作失败");
		}else{
			s.put(ApplicationUtils.STATUS, "1");
			s.put(ApplicationUtils.MSG, "操作成功");
			
			TracelogboWithBLOBs tl = MyTools.getLog(jedisCache, token, request);
			tl.setEntitytypename("c_family_member");
			tl.setEntityid(user_id);
			tl.setLogcategory(2);
			tl.setLogdescription(MyTools.getChangeByMap(m,"修改"));
			int effect=tracelogboMapper.insert(tl);
			System.out.println(effect);
		}
		return s;
	}

	@Override
	public ApiUser selectUserDetail() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Map<String, Object>> queryUserImage(List<String> list) {
		return apiUserDetailMapper.queryUserImage(list);
	}

	@Override
	@Log("UserApiServiceImpl:function[registerByAssist]")
	public Map<String, Object> registerByAssist(User user,HttpServletRequest request) throws Exception {
		Map<String, Object> m = new HashMap<String, Object>();
		
		String user_id = ApplicationUtils.randomUUID();
		user.setId(user_id);
		User s = new User();
		
		if (ApplicationUtils.isNotNull(user.getPhone())) {
			if (SpUtil.validatePhone(user.getPhone())) {
//						s.setPhone(user.getPhone());
				s.setUsername(user.getPhone());
				s.setPhone(user.getPhone());
			} else {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请输入正确的手机号");
				return m;
			}
		} else {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入手机号");
			return m;
		}
		
		
		List<User> list = this.userMapper.selectByWhereStr(s);
		if ((ApplicationUtils.isNotNull(list)) && (list.size() > 0)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "用户已存在");
			return m;
		}
		
		List<User> listp = this.userMapper.selectByPhone(s);
		if ((ApplicationUtils.isNotNull(listp)) && (listp.size() > 0)) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "该手机号已被注册");
			return m;
		}
		
		user.setPassword("123456");//创建的锁定账户密码统一为123456
		insertUserFamily(user, "1",true,request);
//				this.jedisCache.setEx(user_uuid, JedisCont.JEDIS_EXPRISE,
//						user_id);
		String token = ApplicationUtils.randomUUID();
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "注册成功");
		ApiUser dataSet = this.apiUserDetailMapper
				.selectUserDetail(user_id);
		if(dataSet!=null){
//			jedisCache.rpush(token, dataSet.getC_user_id());//0
//			jedisCache.rpush(token, dataSet.getC_role_id());//1
//			jedisCache.rpush(token, dataSet.getC_family_id());//2
//			jedisCache.rpush(token, dataSet.getUsername());//3
//			jedisCache.rpush(token, dataSet.getMember_name());//4
//			jedisCache.expire(token, JedisCont.JEDIS_EXPRISE);
			m.put(ApplicationUtils.DATASET, dataSet);
			m.put("token", token);
		}
		return m;
	}

	@Override
	public Map<String, Object> checkPhoneToken(String phone, String valnum,String type) {
		Map<String,Object> m = Maps.newHashMap();
		if (ApplicationUtils.isNotNull(phone)) {
			if (!SpUtil.validatePhone(phone)) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请输入正确的手机号");
				return m;
			}
		} else {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "请输入手机号");
			return m;
		}
		if(!jedisCache.exists(phone)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码已过期，请重新发送");
			return m;
		}
		
		if(StringUtils.isBlank(valnum)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码不可为空");
			return m;
		}
		
		String val_num = jedisCache.get(phone);
		if(!valnum.equals(val_num)){
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "验证码不正确");
			return m;
		}
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "验证通过");
		return m;
	}

//	@Override
//	public Map<String, Object> sendPhoneValnum(String phone, String type)
//			throws Exception {
//		Map<String, Object> s = new HashMap<String, Object>();
//		
//		if (ApplicationUtils.isNotNull(phone)) {
//			if (!ApplicationUtils.validatePhone(phone)) {
//				s.put(ApplicationUtils.STATUS, "0");
//				s.put(ApplicationUtils.MSG, "请输入正确的手机号");
//				return s;
//			}
//		} else {
//			s.put(ApplicationUtils.STATUS, "0");
//			s.put(ApplicationUtils.MSG, "请输入手机号");
//			return s;
//		}
//		
//		int overTime = 120;
//		String overStr = "2";
//		
//		if("1".equalsIgnoreCase(type)){
//			overTime = 90;
//			overStr = "1.5";
//		}
//		
//		if(jedisCache.exists(phone)){
//			String ovt = jedisCache.hget(phone, "overTime");
//			s.put(ApplicationUtils.STATUS, "0");
//			s.put(ApplicationUtils.MSG, "验证码已发送，3分钟后可再次发送");
//			return s;
//		}else{
//			int[] arrNum = ApplicationUtils.randomArray(0, 9, 6);
//			String pwd_valnum = String.valueOf(arrNum[0])+
//					String.valueOf(arrNum[1])+
//					String.valueOf(arrNum[2])+
//					String.valueOf(arrNum[3])+
//					String.valueOf(arrNum[4])+
//					String.valueOf(arrNum[5]);
//			jedisCache.hset(phone, "valnum", pwd_valnum);
//			jedisCache.hset(phone, "overTime", overTime+"");
////			jedisCache.setEx(phone, 600, pwd_valnum);
//			jedisCache.expire(phone, 600);
//			Ihuyi info = new Ihuyi();
//			info.setMobile(phone);
////			String content = "您的验证码是：【"+pwd_valnum+"】。请不要把验证码泄露给其他人。";
//			String content = "【"+pwd_valnum+"】。请在【"+overStr+"】分钟内使用，请不要把验证码泄露给其他人！";
//
//			info.setContent(content);
//			Status st = ihuyiServiceImpl.sendSms(info);
//			if("0".equalsIgnoreCase(st.getStatus())){
//				s.put(ApplicationUtils.STATUS, "1");
//				s.put(ApplicationUtils.MSG, "验证码发送成功");
//				SpUtil.setPhoneLog(mongoService,"1",phone,pwd_valnum,content);
//				
//				return s;
//			}else{
//				s.put(ApplicationUtils.STATUS, "0");
//				s.put(ApplicationUtils.MSG, "验证码发送失败");
//				SpUtil.setPhoneLog(mongoService,"0",phone,pwd_valnum,content);
//				return s;
//			}
//		}
//	}
}